package com.bsh.serviceImpl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.bsh.mybatis.model.Module;
import com.bsh.repository.DaoModule;
import com.bsh.service.ModuleService;
import com.bsh.utils.Pager;
import com.mysql.jdbc.StringUtils;

@Service
@Transactional
public class ModuleServiceImpl implements ModuleService {
	@Autowired
	private DaoModule moduleDao;
	
	/* (non-Javadoc)
	 * @see com.bsh.serviceImpl.ModuleService#getAllModule()
	 */
	@Override
	public List<Module> getAllModule(){
		List<Module> list = moduleDao.getAllMoudle();
		return list;
	}
	
	
	/* (non-Javadoc)
	 * @see com.bsh.serviceImpl.ModuleService#getPage(com.bsh.utils.Pager, java.lang.String, java.lang.String)
	 */
	@Override
	public List<Map<String, Object>> getPage(Pager pager,String userName,String email) {
		StringBuilder sb =new StringBuilder();
		if(!StringUtils.isNullOrEmpty(userName))
			sb.append(String.format(" and u.name = '%s'",userName.trim()));
		if(!StringUtils.isNullOrEmpty(email))
			sb.append(String.format(" and u.email = '%s'",email.trim()));		
		List<Map<String, Object>> list = moduleDao.getPage(pager,sb.toString());
		return list;
	}
	
	
	/* (non-Javadoc)
	 * @see com.bsh.serviceImpl.ModuleService#getAdminModule(int)
	 */
	@Override
	public List<Module> getAdminModule(int adminId){
		List<Module> list = moduleDao.getAdminModule(adminId);
		return list;
	}
	
}






